﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Core.h".
//-------------------------------------------------------------------

#ifdef  COMPILER_GCC

#ifndef _UXS_GCC_COMPILER_H
#define _UXS_GCC_COMPILER_H

#pragma once


// Version //

#define COMPILER_VERSION		(((__GNUC__)*100) + (__GNUC_MINOR__*10) + (__GNUC_PATCHLEVEL__))

//-------------------------------------------------------------------



// Export //

#ifdef PLATFORM_WINDOWS
#	define UX_DLL_EXPORT			__attribute__ (dllexport)
#	define UX_DLL_IMPORT			__attribute__ (dllimport)
#	define UX_DLL_PRIVATE			
#else
#	define UX_DLL_EXPORT			__attribute__ (visibility("default"))
#	define UX_DLL_IMPORT			__attribute__ (visibility("default"))
#	define UX_DLL_PRIVATE			__attribute__ (visibility("hidden"))
#endif


//-------------------------------------------------------------------



// Compiler Settings //

#if !defined( PLATFORM_ANDROID )
#	define UX_FUNCTION_NAME			__func__
#else
#	define UX_FUNCTION_NAME			"unknown function"
#endif

// 
#define	UX_ALIGN( _size )			__attribute__( packed, aligned( _size ) )

//
#define UX_ALIGN_OF( _type )		__alignof( _type )	// or __alignof__

// 
#define	UX_FORCE_INLINE				__inline__ __attribute__((always_inline))

// 
#define UX_NO_INLINE				__attribute__ ((noinline))

// 
#define	UX_NOOP						// TODO

// 
#define	UX_ASSUME( _cond )			{ if ( !(_cond) ) __builtin_unreachable(); }

// 
#define UX_NO_VTABLE				// TODO

// 
#if !defined( PLATFORM_ANDROID )
#	define	UX_RESTRICT				__restrict__
#else
#	define	UX_RESTRICT
#endif

// 
#define	UX_NO_ALIAS					// TODO

// 
#define	UX_RESTRICT_PTR				// TODO

// 
#define UX_THREAD_LOCAL				__thread

// 
#if COMPILER_VERSION >= 470
#	define UX_NULL_PTR				nullptr
#else
#	define UX_NULL_PTR				__null
#endif

// 
#define UX_NO_RETURN				__attribute__ ((noreturn))

// 
#define __CDECL						// nothing


//-------------------------------------------------------------------



// C++ 11 features //

// final, override, constexpr, decltype
#if COMPILER_VERSION < 470
#	define final
#	define override
#	define constexpr
#	define decltype							__typeof__
#	define noexcept							throw()
#endif


// variable arguments in macro
#if COMPILER_VERSION >= 430
#	define ARGS(...)						__VA_ARGS__
#	define __UX_EMPTY_ARGS(...)		
#endif


// right value reference
#if COMPILER_VERSION >= 460
#	define UX_RVALUE_REFERENCE_SUPPORTED	1
#	define RVALUE_REFERENCE_ONLY			ARGS
#	define WITHOUT_RVALUE_REF_ONLY			__UX_EMPTY_ARGS
#else
#	define UX_RVALUE_REFERENCE_SUPPORTED	0
#	define RVALUE_REFERENCE_ONLY			__UX_EMPTY_ARGS
#	define WITHOUT_RVALUE_REF_ONLY			ARGS
#endif


// auto
#if COMPILER_VERSION >= 460
#	define UX_AUTO_SUPPERTED				1
#else
#	define UX_AUTO_SUPPERTED				0
#	define auto								STATIC_WARNING( "auto not supported" )
#endif


// static assert
#if ( COMPILER_VERSION < 460 )
#	define  __UX_UNIQUE_STATIC_ASSERT_NAME( a )	a##__LINE__
#	define	static_assert( _b_val, _text )		typedef int	__UX_UNIQUE_STATIC_ASSERT_NAME( __static_assert_ ) [ (_b_val) ? 1 : 0 ]
#endif

//-------------------------------------------------------------------



// Other //

#ifndef PLATFORM_ANDROID
#	define UX_BREAK_POINT()		__asm__("int3")		// or asm("int $3");
#else
#	define UX_BREAK_POINT()		{}
#endif


//-------------------------------------------------------------------

#endif	// _UXS_GCC_COMPILER_H
#endif	// COMPILER_GCC